home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1138 / source.zip / RECLAIM.C < prev    next >
C/C++ Source or Header  |  1995-01-18  |  2KB  |  79 lines

  1. /*      reclaim.c -- Data structure memory reclaimer 
  2.     This file is part of Paperboy, an offline mail/newsreader for Windows
  3.     Copyright (C) 1995  Michael H. Vartanian
  4.         vart@clark.net
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include <stdlib.h>
  22. #include "soup.h"
  23. #include "error.h"
  24. #include "reclaim.h"
  25. #include "structs.h"
  26.  
  27. void reclaimgroup (struct llareas * cur)
  28. {
  29.     cur->magic=0;
  30.     reclaimmsg(cur->head);
  31.     free(cur->name);
  32.     free(cur->prefix);
  33.     free(cur->desc);
  34. }
  35.  
  36. void reclaimareas(struct llareas * cur)
  37. /* Blows away entire data structure, should contain most every
  38.  * memory leak within the linked lists.
  39.  */
  40. {
  41.     struct llareas * prev;
  42.  
  43.     while (cur!=NULL)
  44.     {
  45.         reclaimgroup(cur);
  46.         prev=cur;
  47.         cur=cur->next;
  48.         free(prev);
  49.     }
  50. }
  51.  
  52. void sanity(struct llmsg * cur)
  53. {
  54.     while (cur!=NULL)
  55.     {
  56.         assert(cur->magic==MSGMAGIC);
  57.         cur=cur->next;
  58.     }
  59. }
  60.  
  61. void reclaimmsg(struct llmsg * cur)
  62. {
  63.     struct llmsg * prev;
  64.  
  65.     sanity(cur);
  66.  
  67.     while (cur!=NULL)
  68.     {
  69.         assert(cur->magic==MSGMAGIC);
  70.         cur->magic=0;
  71.         free(cur->subject);
  72.         free(cur->author);
  73.         free(cur->date);
  74.         prev=cur;
  75.         cur=cur->next;
  76.         free(prev);
  77.     }
  78. }
  79.